package uk.co.leandro.views
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import flashx.textLayout.accessibility.TextAccImpl;
	
	public class GameOverScreen extends Sprite
	{
		public static const PLAY_AGAIN:String = "playAgainEvent";
		
		
		[Embed(source="assets/gameover.png")]
		private var BG:Class;
		
		[Embed(source="assets/playagain.png")]
		private var PlayAgainButton:Class;
		
		private var playAgainButton:Bitmap;
		private var scoreText:TextField;
		private var format:TextFormat;
		
		public function GameOverScreen()
		{
			super();
			
			var bg:Bitmap = new BG();
			addChild(bg);
			
			playAgainButton = new PlayAgainButton();
			var buttonSprite:Sprite = new Sprite();
			buttonSprite.x = bg.width/2-playAgainButton.width/2;
			buttonSprite.y = 400;
			
			buttonSprite.addChild(playAgainButton);
			addChild(buttonSprite);
			buttonSprite.addEventListener(MouseEvent.CLICK, playAgainHandler);
			
			format = new TextFormat();
			format.font="Verdana";
			format.size=24;
			format.color = 0xFFFFFF;
			format.align = TextFormatAlign.CENTER;
			
			scoreText = new TextField();
			scoreText.text = "      ";
			scoreText.x = bg.width/2-scoreText.width/2;
			scoreText.y = 300;
			scoreText.setTextFormat(format);
			addChild(scoreText);
		}
		
		public function setScore(score:int):void
		{
			scoreText.text = score.toString();
			scoreText.setTextFormat(format);
		}
		
		private function playAgainHandler(event:Event):void
		{
			dispatchEvent(new Event(PLAY_AGAIN));
		}
	}
}